package com.fly.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fly.common.R;
import com.fly.pojo.Blog;
import com.fly.pojo.Blogpojo;
import com.fly.pojo.Tag;
import com.fly.pojo.Type;
import com.fly.service.TypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/type")
public class TypeController {
    @Autowired
    private TypeService typeService;
    @GetMapping("/getType")
    public R<Page> getType(int page, int pageSize){
        Page<Type> typePage =new Page<>(page,pageSize);

        typeService.page(typePage);


        return R.success(typePage);
    }

    @PostMapping("/save")
    public R<String> save(@RequestBody Type type) {

        System.out.println(type);
//        type.setName(name);
       typeService.save(type);
        return R.success("成功");
    }

    @PostMapping("/update")
    public R<String> update(@RequestBody Type type) {

        System.out.println(type);
//        type.setName(name);
        typeService.updateById(type);
        return R.success("成功");
    }

    @GetMapping("/{id}")
    public R<Type> edit(@PathVariable Long id){
        Type type =new Type();
        type =typeService.getById(id);


        return R.success(type);
    }

    @DeleteMapping
    public R<String> deleteBolg(@RequestBody Map id ) {
        Integer idd= (Integer) id.get("id");

        typeService.removeById(idd);
        return R.success("删除成功");
    }

}
